//
//  HPRequest.h
//  Network
//
//  Created by phq on 2019/7/4.
//  Copyright © 2019 phq. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "HPRequestModel.h"
#import "HPInfo.h"

FOUNDATION_EXPORT NSString * _Nonnull const PHNetworkDidChangeNotification;

typedef NS_ENUM(NSInteger, HPNetworkStatus) {
    HPNetworkStatusUnknown          = -1,
    HPNetworkStatusNotReachable     = 0,
    HPNetworkStatusReachableViaWWAN = 1,
    HPNetworkStatusReachableViaWiFi = 2,
};

typedef NS_ENUM(NSInteger, HPNetworkAccess) {
    HPNetworkAccessRelease,
    HPNetworkAccessDebug,
    HPNetworkAccessPre,
    HPNetworkAccessDRY,
};

NS_ASSUME_NONNULL_BEGIN

#define HPNetworking [HPRequest shareInstance]
@interface HPRequest : NSObject
/* 方便server通过请求头查阅日志 */
@property (nonatomic,copy,nullable) NSString *userId;
/* net status */
@property (readonly,nonatomic) BOOL hasNetwork;
@property (readonly,nonatomic) HPNetworkStatus networkStatus;
/* java access */
@property (nonatomic,assign) HPNetworkAccess access;
@property (nonatomic,copy) NSString *accessDRY; // if access=HPNetworkAccessDRY,accessDRY bring into effect.

/// 单列
+ (HPRequest *)shareInstance;

// 4.0弃用
- (void)initPhpApi:(NSString *_Nonnull)url ver:(NSString *_Nonnull)ver end:(HPCallBlock _Nullable)complete; //DEPRECATED_MSG_ATTRIBUTE("Please use - initWebServe:ver:url:end:");
- (void)initPhpApi4:(NSString *_Nonnull)url ver:(NSString *_Nonnull)ver end:(HPCallBlock _Nullable)complete; //DEPRECATED_MSG_ATTRIBUTE("Please use - initWebServe:ver:url:end:");
- (void)initYewenApi:(NSString *_Nonnull)url ver:(NSString *_Nonnull)ver end:(HPCallBlock _Nullable)complete;// DEPRECATED_MSG_ATTRIBUTE("Please use - initWebServe:ver:url:end:");
- (void)initJavaApi:(NSString *_Nonnull)url ver:(NSString *_Nonnull)ver end:(HPCallBlock _Nullable)complete DEPRECATED_MSG_ATTRIBUTE("Please use - initJavaWebServe:");
- (void)initJavaLiveApi:(NSString *_Nonnull)url ver:(NSString *_Nonnull)ver end:(HPCallBlock _Nullable)complete; //DEPRECATED_MSG_ATTRIBUTE("Please use - initJavaWebServe:");
- (void)initJavaYpApi:(NSString *_Nonnull)url ver:(NSString *_Nonnull)ver end:(HPCallBlock _Nullable)complete; //DEPRECATED_MSG_ATTRIBUTE("Please use - initJavaWebServe:");
- (void)initJavaNewApi:(NSString *_Nonnull)url ver:(NSString *_Nonnull)ver end:(HPCallBlock _Nullable)complete;
- (void)initJavaWebServeApi:(NSString *_Nonnull)url ver:(NSString *_Nonnull)ver end:(HPCallBlock _Nullable)complete;

// 4.0新增
- (void)initJavaWebServe:(HPCallBlock _Nullable)complete;
- (void)initWebServe:(ATokenType)type ver:(NSString *_Nonnull)ver url:(NSString *_Nonnull)url end:(HPCallBlock _Nullable)complete;

/// 网络请求POST
/// @param model requestModel 请求模型
/// @param bSucceed 成功回调
/// @param bFailure 失败回调
- (void)postWithModel:(__kindof HPRequestModel *_Nonnull)model
             succeed:(void (^_Nullable)(id _Nullable result))bSucceed
              failure:(void (^_Nullable)(NSString *_Nullable error))bFailure;

/// 获取HPInfo
- (HPInfo *)infoOnType:(ATokenType)type;

/// 打印网络请求信息。非DEBUG自动关闭。
/// @param logHeader 打印请求头信息，默认NO
/// @param logParams 打印传参信息，默认NO
- (void)logHeader:(BOOL)logHeader params:(BOOL)logParams;

/// 更改当前accessToken和secret值
/// @param type 接口访问类型
/// @param update 是否忽略本地缓存从服务器更新，Default is NO。
- (void)configAccessToken:(ATokenType)type forcedUpdate:(BOOL)update;

/// 开始监听网络状态。通过监听PHNetworkDidChangeNotification通知获取HPNetworkStatus状态变化值
- (void)startMonitoring;

/// 获取设备UUID
+ (NSString *_Nonnull)getMacAddress;

@end

NS_ASSUME_NONNULL_END
